from vector import vector
from rendering import *
col = []
def getByName(string,l):
    for i in range(0,len(l)):
        if str(l[i]) == string:
            return l[i+1]
class load_map:
    def __init__(self,path,surface):
        self.mapa = []
        self.surface = surface
        f = open(path,"r")
        fString = f.read()
        f.close()
        fString = fString.split(";")
        self.entity = eval(fString[0])
        textures = eval(fString[1])
        self.size = fString[2].split("x")
        self.images = []
        for i in textures:
            self.images.append(i)
            self.images.append(i_object("./textures/"+i,surface))
        for i in range(3,int(self.size[0])*int(self.size[1])):
            if str(eval(fString[i])[2]) == "True":
                print "TRUE"
                col.append(eval(fString[i])[0])
            self.mapa.append(eval(fString[i]))
    def changeMap(self,path):
        self.mapa = []
        f = open(path,"r")
        fString = f.read()
        f.close()
        fString = fString.split(";")
        self.entity = eval(fString[0])
        textures = eval(fString[1])
        self.size = fString[2].split("x")
        self.images = []
        for i in textures:
            self.images.append(i)
            self.images.append(i_object("./textures/"+i,self.surface))
        for i in range(3,int(self.size[0])*int(self.size[1])):
            self.mapa.append(eval(fString[i]))
    def returnEntityList(self):
        return self.entity
    def redraw(self):
        for i in range(0,(int(self.size[0])*int(self.size[1]))-3):
            pos = self.mapa[i][0].split("x")
            getByName(self.mapa[i][1],self.images).draw(vector(int(pos[0])*10,int(pos[1])*10))
 
